<template>
  <div id="unit" class="flex" >
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfsearch' v-ref:cri>
        <div novalidate class="form-inline" partial>
          <div class="form-group form-input-group">
            <label for="startDate" class="control-label">开始日期:</label>
            <datepicker id="startDate" placeholder="开始日期" width='100%'
              v-model="model.startDate"
              :value.sync="model.startDate"
              :disabled-days-of-Week="[]"
              condition="f_delivery_date >= '{}' "
              :format="'yyyy-MM-dd 00:00:00'"
              :show-reset-button="reset">
            </datepicker>
          </div>

          <div class="form-group form-input-group">
            <label for="endDate" class="control-label">结束日期:</label>
            <datepicker id="endDate" placeholder="结束日期" width='100%'
              v-model="model.endDate"
              :value.sync="model.endDate"
              condition="f_delivery_date <= '{}' "
              :disabled-days-of-Week="[]"
              :format="'yyyy-MM-dd 23:59:59'"
              :show-reset-button="reset">
            </datepicker>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="search()" v-el:cx>查询</button>
            <export-excel :data="$parent.$parent.getPargram()"
            sqlurl="rs/logic/exportfile" :bean="'月汇总查询导出'"></export-excel>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>月份</th>
            <th>用气性质</th>
            <th>笔数</th>
            <th>气量</th>
            <th>应收金额</th>
            <th>实收金额</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;"  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{$index+1}}</td>
          <td v-if="model.rows[$index-1] && model.rows[$index-1].f_delivery_date === row.f_delivery_date"></td>
          <td v-else  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{row.f_delivery_date}}</td>
          <td  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{row.f_gasproperties}}</td>
          <td  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{row.times}}</td>
          <td  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{row.f_pregas}}</td>
          <td  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{row.f_preamount}}</td>
          <td  :class = "{'bg-info' : row.f_delivery_date === '小计', 'bg-success' : row.f_delivery_date === '总计' }">{{row.f_collection}}</td>
        </template>
      </data-grid>
  </criteria-paged>
 </div>
</template>
<script>
import { PagedList } from 'vue-client'
// import AppData from '../../../../stores/AppData'
import * as Util from '../../../Util'

export default {
  title: '月汇总信息',
  data () {
    return {
      model: new PagedList('rs/sql/monthSummarize', 150,
          {startDate: '"' + Util.toStartAndEndDateString()[0] + ' 00:00:00' + '"',
           endDate: '"' + Util.toStartAndEndDateString()[1] + ' 23:59:59' + '"'
          })
    }
  },
  props: [],
  ready () {
    this.$refs.paged.$refs.cri.model.startDate = Util.toStartAndEndDateString()[0] + ' 00:00:00'
    this.$refs.paged.$refs.cri.model.endDate = Util.toStartAndEndDateString()[1] + ' 23:59:59'
    this.model.search()
  },
  methods: {
    search () {
      this.model.search('1=1')
    },
    selfsearch (arr) {
      this.model = new PagedList('rs/sql/monthSummarize', 150, {startDate: '"' + this.getPargram().startDate + '"', endDate: '"' + this.getPargram().endDate + '"'})
      this.model.search()
    },
    getPargram () {
      let startDate = this.$refs.paged.$refs.cri.model.startDate
      let endDate = this.$refs.paged.$refs.cri.model.endDate
      return {startDate: startDate, endDate: endDate}
    }
  },
  computed: {

  }
}
</script>
